package com.homework.action;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.homework.bean.CourseBean;
import com.homework.bean.InformBean;
import com.homework.bean.UserBean;
import com.homework.service.InformService;

public class InformAddAction {

	private static InformService informService;
	private int courseId;
	private String informHead;
	private String informBody;

	public InformAddAction() {
		informService = new InformService();
	}

	public int getCourseId() {
		return courseId;
	}

	public void setCourseId(int courseId) {
		this.courseId = courseId;
	}

	public String getInformHead() {
		return informHead;
	}

	public void setInformHead(String informHead) {
		this.informHead = informHead;
	}

	public String getInformBody() {
		return informBody;
	}

	public void setInformBody(String informBody) {
		this.informBody = informBody;
	}

	// 发布通知
	public String informAdd() throws SQLException {

		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();

		// courseBean
		CourseBean courseBean = new CourseBean();
		courseBean.setCourseId(String.valueOf(this.getCourseId()));
		// userBean
		UserBean userBean = new UserBean();
		userBean.setUserId(String.valueOf(session.getAttribute("userId")));
		//  informBean
		InformBean informBean = new InformBean();
		informBean.setInformHead(this.getInformHead());
		informBean.setInformBody(this.getInformBody());
		// courseId
		int courseIdTemp = this.getCourseId();

		informService.informAdd(courseBean,userBean,informBean);
		request.setAttribute("courseId", courseIdTemp);

		return "Success";
	}
}
